﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;

namespace DAL
{
    public class ChiTietHoaDon_DAL
    {
        public DataProvider _provider = new DataProvider();
		
		public ChiTietHoaDon_DAL()
		{
			_provider.connect();
		}

        public void ThemChiTietHoaDon(ChiTietHoaDon_DTO cthd)
        {
            string insertCommand = @"INSERT INTO CHITIETHOADON (MaHP, MaHD) VALUES('" +
                   cthd.MaHP + "'," +
                   cthd.MaHD + ")";

            _provider.executeNonQuery(insertCommand);
        }
        public List<ChiTietHoaDon_DTO> DS_ChiTietHoaDon()
        {

            SqlDataReader reader = (SqlDataReader)_provider.executeQuery("DS_ChiTietHoaDon");

            List<ChiTietHoaDon_DTO> List_CTHD = new List<ChiTietHoaDon_DTO>();

            while (reader.Read())
            {
                ChiTietHoaDon_DTO cthd = new ChiTietHoaDon_DTO();
                cthd.MaHD = int.Parse(reader["MaHD"].ToString());
                cthd.MaHP = reader["MaHP"].ToString();
            
                List_CTHD.Add(cthd);

            }

            reader.Close();
            return List_CTHD;
        }

        
        
    }
}
